<template>
    <div class="search-wapper">
        <van-nav-bar
                title="搜索"
                left-text="返回"
                left-arrow
                fixed
                @click-left="onClickLeft"
        >
            <van-icon name="arrow-left" slot="left"/>
            <!--<van-icon name="search" slot="right"/>-->
        </van-nav-bar>
        <div class="search-content">
            <van-cell-group>
                <van-field v-model="itemid" label="物资编号" placeholder="请输入物资编号"/>
                <van-field
                        v-model="description"
                        label="物资名称"
                        placeholder="请输入物资名称"
                />
                <van-field
                        v-model="subsystemid"
                        label="专业"
                        is-link
                        readonly
                        @click="showZhuanye"
                        placeholder="请输入专业"
                />
                <van-field
                        v-model="refrence"
                        label="采购方式"
                        is-link
                        readonly
                        @click="showZhuanye1"
                        placeholder="请输入采购方式"
                />
                <van-field
                        v-model="spec"
                        label="规格型号"
                        placeholder="请输入规格型号"
                />
            </van-cell-group>
        </div>
        <div class="button-content">
            <van-button type="primary" round style="width: 100%" @click="submitInfo"
            >查询
            </van-button
            >
        </div>
        <van-action-sheet v-model="show1" :actions="actions1" @select="onSelect1"/>

        <van-action-sheet v-model="show" :actions="actions" @select="onSelect"/>
    </div>
</template>

<script>
	import { getComcode } from "@/api/goods.js";
    export default {
        name: "Search",
        data() {
            return {
                userInfo: {},
                show: false,
                show1: false,
                itemid: "",
                description: "",
                refrence: "",
                spec: "",
                subsystemid: "",
				comCodeList:[],
                actions1:[{name: "集采"}, {name: "自购"}, {name: "甲供"}],
                actions: [{name: "选项1"}, {name: "选项2"}, {name: "选项3"}]
            };
        },
        methods: {
			getComcode() {
			  getComcode().then(res => {
				  var list=res.data;
				  for (let i=0;i<list.length;i++) {
					  console.info(list[i])
				  	list[i].name=list[i].codevalue
				  }
						this.actions=list
					});
			},
            submitInfo() {
                this.$router.push({
                    path: "/home",
                    query: {
                        itemid: this.itemid,
                        refrence: this.refrence,
                        spec: this.spec,
                        subsystemid: this.subsystemid,
                        description: this.description
                    }
                });
            },
            onClickLeft() {
                this.$router.back(-1);
            },
            onSelect(item) {
                // 默认情况下，点击选项时不会自动关闭菜单
                // 可以通过 close-on-click-action 属性开启自动关闭
                this.show = false;
                // Toast(item.name);
                console.log("onSelect======", item.codeid);
                this.subsystemid = item.codeid;
            },
        onSelect1(item) {
            // 默认情况下，点击选项时不会自动关闭菜单
            // 可以通过 close-on-click-action 属性开启自动关闭
            this.show1 = false;
            // Toast(item.name);
            console.log("onSelect======", item.codeid);
            this.refrence = item.name;
        },
            clickRight() {
                console.log("=====clickRight===");
                this.show = true;
            },
            showZhuanye() {
                console.log("=====ss===");
                this.show = true;
            },
            showZhuanye1() {
                console.log("=====ss===");
                this.show1 = true;
            }
        },
  created() {
    // console.log(this.$route.query.id)
    this.getComcode();
  }
    };
</script>

<style scoped lang="scss">
    .search-wapper {
        position: relative;
        .search-content {
            position: relative;
            /*top: 46px;*/
            /*height: calc(100% - 50px);*/
            /*margin-bottom: 10px;*/
            margin: 20px;
            padding: 5px;
            background: #fff;
            border-radius: 8px;
            top: 37%; /*偏移*/
            transform: translateY(-50%);
        }
        .button-content {
            position: relative;
            top: 55%;
            transform: translateY(-50%);
            margin-top: 20px;
            padding: 0px 20px;
        }
    }
</style>
